package com.luyue.zagj.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.luyue.zagj.MainActivity;
import com.luyue.zagj.MyApplication;
import com.luyue.zagj.R;
import com.luyue.zagj.activity.home.ApplyLabelActivity;
import com.luyue.zagj.activity.home.CallPoliceActivity;
import com.luyue.zagj.activity.home.DrivingActivity;
import com.luyue.zagj.activity.home.InsuranceClaimsActivity;
import com.luyue.zagj.activity.home.RapidRepairActivity;
import com.luyue.zagj.activity.home.TravelRecordActivity;
import com.luyue.zagj.activity.home.VehicleInfoActivity;
import com.luyue.zagj.service.GPSService;
import com.luyue.zagj.utils.Windowutil;
import com.umeng.analytics.MobclickAgent;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/8/24 0024.
 */
public class HomeFragment extends Fragment {
    private static final String PHONE_NUMBER = "110";
    private static final String INSURANCE_PHONE_NUMBER = "95518";
    /*  @Bind(R.id.travel_record_top_rl)
      FrameLayout travelRecordTopRl;*/
    @Bind(R.id.iv_lock)
    ImageView ivLock;
    @Bind(R.id.home_apply_label)
    ImageView homeApplyLabel;
    @Bind(R.id.home_travel_record)
    ImageView homeTravelRecord;
    @Bind(R.id.home_vehicle_info)
    ImageView homeVehicleInfo;
    @Bind(R.id.home_call_police)
    ImageView homeCallPolice;
    @Bind(R.id.home_rapid_repair)
    ImageView homeRapidRepair;
    @Bind(R.id.home_insurance)
    ImageView homeInsurance;
/*    @Bind(R.id.tv_lock)
    TextView tvLock;
    @Bind(R.id.home_apply_label)
    RelativeLayout homeApplyLabel;
    @Bind(R.id.home_vehicle_info)
    RelativeLayout homeVehicleInfo;
    @Bind(R.id.home_rapid_repair)
    RelativeLayout homeRapidRepair;
    @Bind(R.id.home_travel_record)
    RelativeLayout homeTravelRecord;
    @Bind(R.id.home_call_police)
    RelativeLayout homeCallPolice;
    @Bind(R.id.home_insurance)
    LinearLayout homeInsurance;*/

    private View view;
    private int locknum = 1;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        initStateBar();

        view = inflater.inflate(R.layout.main_fragment_home, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //initViewpager();
    }

    public void initView() {

    }

    private void initStateBar() {
        Windowutil.clearWindow((MainActivity) getActivity(), R.color.police_blur);
    }

    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.iv_lock, R.id.home_apply_label,
            R.id.home_vehicle_info, R.id.home_rapid_repair,
            R.id.home_travel_record, R.id.home_call_police,
            R.id.home_insurance})
    public void onClick(View view) {
        Intent it = new Intent();
        switch (view.getId()) {
            case R.id.iv_lock:
                if (locknum == 1) {
                    ivLock.setImageResource(R.drawable.gray_unlock);
                    locknum = 0;
                } else {
                    ivLock.setImageResource(R.drawable.gray_lock);
                    locknum = 1;
                }
                break;
            case R.id.home_apply_label:
                it.setClass(getContext(), ApplyLabelActivity.class);
                startActivity(it);
                break;
            case R.id.home_vehicle_info:
                it.setClass(getContext(), VehicleInfoActivity.class);
                startActivity(it);
                break;
            case R.id.home_rapid_repair:
                it.setClass(getContext(), RapidRepairActivity.class);
                startActivity(it);
                break;
            case R.id.home_travel_record:
                Intent service=new Intent(MyApplication.getContext(), GPSService.class);
                MyApplication.getContext().startService(service);
                it.setClass(getContext(), DrivingActivity.class);
                startActivity(it);
                break;
            case R.id.home_call_police:
                it.setClass(getContext(), CallPoliceActivity.class);
                startActivity(it);
                break;
            case R.id.home_insurance:
                it.setClass(getContext(), InsuranceClaimsActivity.class);
                startActivity(it);
                break;
        }
    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(MyApplication.getContext());
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onResume(MyApplication.getContext());
    }
}
